package com.linkoog.devtools.intellij.ui.tree;

import jdk.jfr.Description;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;

/**
 *
 */
@Getter
@Description("树形结构数据的结点")
@EqualsAndHashCode(callSuper = true)
public abstract class TreeBaseNode extends DefaultMutableTreeNode {

    @Description("结点显示的内容")
    private final String name;

    @Description("结点显示的图标")
    private final transient Icon icon;

    @Description("鼠标悬浮在结点上展示的内容")
    private final String description;

    public TreeBaseNode(@NotNull String name, Icon icon, String description) {
        this.name = name;
        this.icon = icon;
        this.description = description;
    }

    @Description("添加子节点")
    @Override
    public void add(@NotNull MutableTreeNode newChild) {
        if (newChild instanceof TreeBaseNode) {
            addNode(((TreeBaseNode) newChild));
        }
    }

    private void addNode(@NotNull TreeBaseNode newChild) {
        super.add(newChild);
    }


}
